﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;

namespace StrategyPattern
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("20234714 冯少飞的策略模式");
            while (true)
            {
                int inputLeft = 0;
                int inputRight = 0;
                string operate = "";

                Console.WriteLine("请输入第一个操作数：");
                string leftStr = Console.ReadLine();
                //字符串转整形
                if (!int.TryParse(leftStr, out inputLeft))
                {
                    Console.WriteLine("输入的数据无效，请重新输入");
                    continue;
                }
                Console.WriteLine("请输入运算（策略）方式：");
                operate = Console.ReadLine();
                if (!new string[] { "+", "-", "*", "/" }.Contains(operate))
                {
                    Console.WriteLine("输入的运算符无效，请重新输入");
                    continue;
                }

                Console.WriteLine("请输入第二个操作数：");
                string rightStr = Console.ReadLine();
                //字符串转整形
                if (!int.TryParse(rightStr, out inputRight))
                {
                    Console.WriteLine("输入的数据无效，请重新输入");
                    continue;
                }
                //使用数据进行操作
                Context context = new Context(inputLeft, inputRight, SimpleFactory.CreateCaculation(operate));
                Console.WriteLine($"运算结果：{inputLeft}{operate}{inputRight}={context.Caculation()}");
            }

            Console.ReadKey();
        }
    }
}
